/*
 * Duplicate Detector Copyright (C) 2010 Marco Biscaro <marcobiscaro2112@gmail.com>
 * 
 * This file is part of Duplicate Detector.
 *
 * Duplicate Detector is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Duplicate Detector is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Duplicate Detector.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.duplicatedetector.controller;

import java.awt.Component;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import com.googlecode.duplicatedetector.Constants;
import com.googlecode.duplicatedetector.view.HelpPanel;

/**
 * Shows a general dialog containing the given document and with the given
 * title.
 * 
 * @author Marco Biscaro
 */
public class ShowHelpActionListener implements ActionListener, Constants {

	private String title;
	private URL url;
	private Component comp;

	public ShowHelpActionListener(String title, URL url, Component comp) {
		this.title = title;
		this.url = url;
		this.comp = comp;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Window parent = SwingUtilities.getWindowAncestor(comp);
		JDialog dialog = new JDialog(parent);
		dialog.setTitle(title);
		dialog.setModal(true);
		dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		dialog.setContentPane(new HelpPanel(url));
		dialog.pack();
		dialog.setMinimumSize(dialog.getSize());
		dialog.setLocationRelativeTo(parent);
		dialog.setVisible(true);
	}

}
